-- card: 2102 from stack: in -- bmap block id: 0 -- flags: 0000 -- background id: 3241 -- name: -- part 1 (button) -- low flags: 00 -- high flags: A003 -- rect: left=65 top=279 right=301 bottom=200 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: until mouse press ----- HyperTalk script ----- on mouseUp PopUpPicture 1508,50,54,3,false end mouseUp -- part 2 (button) -- low flags: 00 -- high flags: A003 -- rect: left=65 top=302 right=323 bottom=201 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: until mouse release ----- HyperTalk script ----- on mouseDown PopUpPicture 20377,245,54,2,true end mouseDown -- part 5 (field) -- low flags: 80 -- high flags: 2007 -- rect: left=12 top=26 right=298 bottom=491 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 22 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: -- part 6 (button) -- low flags: 00 -- high flags: A003 -- rect: left=314 top=300 right=322 bottom=435 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Show LSP Source ----- HyperTalk script ----- on mouseUp set the visible of card field 1 to not the visible of card field 1 if the visible of card field 1 is true then set the name of me to "Hide LSP Source" else set the name of me to "Show LSP Source" end mouseUp -- part contents for background part 16 ----- text ----- POPUPPICTURE XCMD version 1.1 Kevin Calhoun PopUpPicture opens a window on top of the current card and displays a picture in it. You can't do anything with the picture except look at it. When you click the mouse (or, alternatively, when you release the mouse) the picture goes away and its window is disposed of. Color pictures (in PICT2 format) will appear in color on a suitably equipped Mac II and will appear in monochrome on any other machine running System 4.1 or later. horse* You tell PopUpPicture what picture to draw by specifying the ID number a resource of type PICT, which can be contained in the current stack or in any other open resource file, including the home stack, HyperCard, or the System file. Any picture you've copied to the clipboard can become a resource of type PICT--use the ClipToPICT XFCN to achieve this transformation and to install the new PICT resource in your stack. A file of type PICT can be converted to a PICT resource using the PICTFileToRes XFCN. INVOKING POPUPPICTURE PopUpPicture takes six parameters, the last two of which are optional. You must specify the ID of the PICT resource you want displayed, the horizontal and vertical coordinates of the top left corner of the window in which the picture will be drawn, and the type of window you want. You may also specify that you want the picture to disappear when the mouse button is next released rather than when it is next pushed. The format of a PopUpPicture call is: PopUpPicture pictureID, top, left, windowKind, «onMouseUp»,«passThru» The pictureID is the ID of the PICT resource you want displayed. The top and left parameters are given as coordinates in the card window coordinate system. A top of 0 and a left of 0 would draw the picture flush against the top left corner of the card window. PopUpPicture will draw three different kinds of windows--a windowKind of 1 produces a modal dialog box (a box with a double border), a windowKind of 2 produces a plain box, and a windowKind of 3 produces a plain box with shadow. If windowKind has any other value, PopUpPicture defaults to a plain box with shadow. (Note that the top left corner of the picture will appear in the same place regardless of which windowKind you request, although the top left corner of the window will vary.) If you want the picture to remain present until the next time the user pushes the mouse button, pass "false" in the onMouseUp parameter. If you want the picture to remain present until the next time the user releases the mouse button, pass "true" in the onMouseUp parameter. If you don't provide the onMouseUp parameter, PopUpPicture will remove the picture on the next push of the mouse button. The event that causes the picture to be removed, a mouseDown if onMouseUp is FALSE, a mouseUp if onMouseUp is TRUE, can be passed on to HyperCard. If you want the event to be passed on so that it generates a HyperTalk message, pass "true" in the passThru parameter. To test this effect, add the passThru parameter to the script of the button "until mouse press." EXAMPLES: PopUpPicture 14990,40,56,3,false PopUpPicture 14990,19,34,2,true REVISION HISTORY 1.0 -- 4/22/88 1.1 -- 7/7/88 -- added passThru option -- part contents for card part 5 ----- text ----- UNIT PopUpPicture; { PopUpPicture XCMD ©1988 by the Trustees of Dartmouth College. } { Written by John K. Calhoun, Courseware Development. } INTERFACE USES XCMDIntf, ColorQuickDraw, ColorWindowMgr; TYPE Str31 = STRING[31]; PROCEDURE Main (paramPtr : XCMDPtr); IMPLEMENTATION PROCEDURE DoJsr (addr : ProcPtr); INLINE $205F, $4E90; FUNCTION EvalExpr (paramPtr : XCmdPtr; expr : Str255) : Handle; BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := ORD(@expr); request := xreqEvalExpr; DoJsr(entryPoint); EvalExpr := Handle(outArgs[1]); END; END; PROCEDURE ZeroToPas (paramPtr : XCmdPtr; zeroStr : Ptr; VAR pasStr : Str255); BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := ORD(zeroStr); inArgs[2] := ORD(@pasStr); request := xreqZeroToPas; DoJsr(entryPoint); END; END; FUNCTION StrToNum (paramPtr : XCmdPtr; str : Str31) : LongInt; BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := ORD(@str); request := xreqStrToNum; DoJsr(entryPoint); StrToNum := outArgs[1]; END; END; FUNCTION PasToZero (paramPtr : XCmdPtr; str : Str255) : Handle; BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := ORD(@str); request := xreqPasToZero; DoJsr(entryPoint); PasToZero := Handle(outArgs[1]); END; END; FUNCTION StrToBool (paramPtr : XCmdPtr; str : Str31) : BOOLEAN; BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := ORD(@str); request := xreqStrToBool; DoJsr(entryPoint); StrToBool := BOOLEAN(outArgs[1]); END; END; FUNCTION NumToStr (paramPtr : XCmdPtr; num : LongInt) : Str31; VAR str : Str31; BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := num; inArgs[2] := ORD(@str); request := xreqNumToStr; DoJsr(entryPoint); NumToStr := str; END; END; PROCEDURE SendCardMessage (paramPtr : XCmdPtr; msg : Str255); BEGIN WITH paramPtr^ DO BEGIN inArgs[1] := ORD(@msg); request := xreqSendCardMessage; DoJsr(entryPoint); END; END; FUNCTION ColorQDExists : BOOLEAN; { See tech note #119 } TYPE WordPtr = ^Integer; CONST ROM85Loc = $28E; TwoHighMask = $C000; VAR myWordPtr : WordPtr; BEGIN myWordPtr := WordPtr(ROM85Loc); ColorQDExists := BitAnd(myWordPtr^, TwoHighMask) = 0; END; FUNCTION GetLocOfCardWindow (paramPtr : XCmdPtr) : point; VAR theResult : Handle; aString : Str255; theLoc : point; BEGIN theResult := EvalExpr(paramPtr, 'item 1 of the loc of card window'); ZeroToPas(paramPtr, theResult^, aString); DisposHandle(theResult); theLoc.h := StrToNum(paramPtr, aString); theResult := EvalExpr(paramPtr, 'item 2 of the loc of card window'); ZeroToPas(paramPtr, theResult^, aString); DisposHandle(theResult); theLoc.v := StrToNum(paramPtr, aString); GetLocOfCardWindow := theLoc; END; PROCEDURE PopItUpAlready (paramPtr : XCMDPtr); VAR parameterCount : INTEGER; pictID : INTEGER; RTop : INTEGER; RLeft : INTEGER; windKind : INTEGER; thePicHandle : PicHandle; r : rect; savePort : grafPtr; myWindow : WindowPtr; anEvent : EventRecord; cardTopLeft : Point; onRelease : boolean; theMask : INTEGER; passThru : BOOLEAN; PROCEDURE passReturnValue (theMsg : Str255); { set theResult and quit } BEGIN paramPtr^.returnValue := PasToZero(paramPtr, theMsg); END; FUNCTION GetParameters (expected : INTEGER) : INTEGER; VAR count : INTEGER; str : Str255; BEGIN count := paramPtr^.paramCount; IF expected <= count THEN BEGIN GetParameters := count; ZeroToPas(paramPtr, paramPtr^.params[1]^, str); pictID := StrToNum(paramPtr, str); ZeroToPas(paramPtr, paramPtr^.params[2]^, str); RLeft := StrToNum(paramPtr, str); ZeroToPas(paramPtr, paramPtr^.params[3]^, str); RTop := StrToNum(paramPtr, str); ZeroToPas(paramPtr, paramPtr^.params[4]^, str); windKind := StrToNum(paramPtr, str); IF count > 4 THEN BEGIN ZeroToPas(paramPtr, paramPtr^.params[5]^, str); onRelease := StrToBool(paramPtr, str); IF count > 5 THEN BEGIN ZeroToPas(paramPtr, paramPtr^.params[6]^, str); passThru := StrToBool(paramPtr, str); END; END ELSE onRelease := FALSE; END ELSE GetParameters := -1; END; BEGIN passThru := FALSE; parameterCount := GetParameters(4); IF parameterCount < 4 THEN passReturnValue('PopUpPicture XCMD 1.1 -- July 7, 1988') ELSE BEGIN thePicHandle := GetPicture(pictID); IF thePicHandle <> NIL THEN BEGIN InitCursor; r := thePicHandle^^.picFrame; {use actual size of picture} cardTopLeft := GetLocOfCardWindow(paramPtr); WITH r, cardTopLeft DO offsetRect(r, -left + rLeft + h, -top + rTop + v); getPort(savePort); {save old port, create new window to fit pict, and prepare to draw there} IF NOT (windKind IN [1..3]) THEN windKind := altDBoxProc; IF ColorQDExists THEN myWindow := NewCWindow(NIL, r, '', TRUE, windKind, POINTER(-1), FALSE, 0) ELSE myWindow := NewWindow(NIL, r, '', TRUE, windKind, POINTER(-1), FALSE, 0); {wStorage} setPort(myWindow); ClipRect(myWindow^.PortRect); {make sure clip region is not empty. See Mac Tech Note #59.} {draw the pic into that window} MoveHHi(Handle(thePicHandle)); HLock(handle(thePicHandle)); DrawPicture(thePicHandle, myWindow^.PortRect); {draw picture, filling the window} { wait for mouse-down or mouse-up } IF onRelease THEN theMask := mupmask ELSE theMask := mdownMask; REPEAT systemTask; UNTIL OSEventAvail(theMask, anEvent); IF NOT passThru THEN IF GetNextEvent(theMask, anEvent) THEN ; {get rid of window and pict; restore port, and exit} DisposeWindow(myWindow); HUnlock(handle(thePicHandle)); {done with the picture here} HPurge(Handle(thePicHandle)); setPort(savePort); END ELSE passReturnValue(CONCAT('Error -- can''t find picture ID', numToStr(paramPtr, pictID), ' .')); END; SendCardMessage(paramPtr, 'go to this card'); END; PROCEDURE Main; BEGIN PopItUpAlready(paramPtr); END; END.